import debounceUtils from '@/core/utils/debounceUtils'
import authManager from '@/core/auth/manager/authManager'
import promiseUtils from '@/core/utils/promiseUtils'
import Oauth2RegisteredClientResponse from '@/core/oauth2/types/model/response/Oauth2RegisteredClientResponse'
import oauth2RegisteredClientServerApi from '@/core/oauth2/serverapi/oauth2RegisteredClientServerApi'

class Oauth2RegisteredClientService {
	getByIdsWithDebounce: (id: string) => Promise<Oauth2RegisteredClientResponse[]> = debounceUtils.define<
		string,
		Oauth2RegisteredClientResponse[]
	>((ids: string[]): Promise<Oauth2RegisteredClientResponse[]> => {
		const userAccessToken = authManager.getAndCheckUserTokenInfo().accessToken
		return promiseUtils.ofResponse(oauth2RegisteredClientServerApi.getByIds(userAccessToken, ids)).check()
	})
}

export default new Oauth2RegisteredClientService()
